package com.hbwxz.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 用户 Service2 - TxConfig
 *
 * @author shenzw
 * @date 2023/12/9
 */
@Service
@Slf4j
public class UserService2 {

    @Resource
    private JdbcTemplate jdbcTemplate;

    /**
     * 申明式事务 - 基于 XML配置（无侵入式）
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager",propagation = Propagation.REQUIRES_NEW)
    public void trans() {
        jdbcTemplate.update("update user_tx set money = ? where id = ?", 1111, 2);
        int i = 1 / 0;
    }

}
